<template>
  <div>
    <el-row>
      <el-col :span="4">
        <el-menu :default-active="$route.path" :router="true">
          <el-menu-item index="/index">
            <i class="el-icon-menu"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <el-menu-item index="/user">
            <i class="el-icon-document"></i>
            <span slot="title">用户管理</span>
          </el-menu-item>
          <el-menu-item index="/article">
            <i class="el-icon-document"></i>
            <span slot="title">帖子管理</span>
          </el-menu-item>
          <el-menu-item index="/category">
            <i class="el-icon-setting"></i>
            <span slot="title">分类管理</span>
          </el-menu-item>
          <el-menu-item index="/config">
            <i class="el-icon-setting"></i>
            <span slot="title">系统字典</span>
          </el-menu-item>
        </el-menu>
      </el-col>
      <el-col :span="20">
        <el-menu mode="horizontal" default-active="1">
          <el-submenu index="1" style="float: right">
            <template slot="title">
              <el-avatar :src="loginUser.avatar"></el-avatar>
              {{ loginUser.nickname }}</template
            >
            <el-menu-item index="1-2">修改密码</el-menu-item>
            <el-menu-item index="1-3" @click="logout">退出登陆</el-menu-item>
          </el-submenu>
        </el-menu>
        <router-view />
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { Message } from "element-ui";
export default {
  name: "indexPage",
  data() {
    return {
      loginUser: {},
    };
  },
  methods: {
    logout() {
      this.getRequest("/user/logout", { id: this.loginUser.id });
      localStorage.removeItem("loginUser");
      localStorage.removeItem("tokenName");
      localStorage.removeItem("tokenValue");
      this.$router.push("/");
      Message({
        message: "退出成功",
        type: "success",
      });
    },
  },
  created() {
    let user = JSON.parse(localStorage.getItem("loginUser"));
    if (!user) {
      Message({
        message: "请登录",
        type: "error",
      });
      this.logout();
    }
    this.loginUser = user;
  },
};
</script>
<style scoped></style>
